const vm =Vue.createApp({
    data(){
       return{
           blog:{
               id:"",
               categoryId:1,
               title:"",
               content:"",
               description:"",
               htmlContent:"",
               categoryTitle:""
           },

       }
    },
    mounted(){
        var blogId=document.getElementById("blogId").value;
        console.log(blogId)
        if (blogId){
          this.blog.id=blogId;

          this.getBlog(blogId);
        }
    },
    methods:{
       save(){
           this.blog.content=testEditor.getMarkdown();
           this.blog.htmlContent=testEditor.getHTML();
           axios.post("/saveBlog",this.blog)
           console.log(this.blog)
       },
        changCategory(e){

            var selectIndex=e.target.selectedIndex;
            var options=e.target.options;
            this.blog.categoryTitle=options[selectIndex].text;
        },
        //获取blog详情
        getBlog(callback){
           axios.get("/api/blog/get/"+this.blog.id).then(res=>{
               this.blog=res.data;
               console.log(this.blog.htmlContent)
               setTimeout(()=>{
                   var content =  res.data.content;
                   var cachecontent = window.localStorage.getItem("kss_blog_content") || "";
                   testEditor.setMarkdown(cachecontent.length>content.length ? cachecontent:res.data.content);
               },300)
           })
        }
    }
}).mount("#main")